package com.itheima.domain;

public class Student implements Comparable<Student>{

    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    //比较方法  根据年龄大小去比
    @Override
    public int compareTo(Student o) {

        //this  o  按照年龄升序
        int result= this.getAge()-o.getAge();
        //当年龄相等时 按照 姓名的排序比
       /* if(result==0){
            return  this.getName().compareTo(o.getName());
        }
        return result;*/
       result=result==0? this.getName().compareTo(o.getName()):result;
       return result;


    }
}
